#@weiXinLayout("我预订的客栈")
#define weiXinMain()
#@navBar("我预订的客栈",contextPath+"/weixin/mine")
<div class="weui-panel" style="margin-top:0px;">
    <div class="weui-panel__bd" id="content">

    </div>
</div>
#end

#define weiXinCss()
#end

#define weiXinJs()
<script type="text/x-mustache" id="template">
     {{#items.list}}
        <div class="weui-media-box weui-media-box_text" data-status="{{status}}" data-id="{{id}}" data-obj_id={{obj_id}}>
            <h4 class="weui-media-box__title">{{name}}</h4>
            <p class="weui-media-box__desc">{{desc}}</p>
            <ul class="weui-media-box__info">
                <li class="weui-media-box__info__meta">{{create_time}}至{{create_time}}</li>
                <li class="weui-media-box__info__meta weui-media-box__info__meta_extra">{{status}}</li>
            </ul>
        </div>
    {{/items.list}}
</script>
<script>

    $(document).ready(function() {

        var pageNum = 1;
        var totalPage =1;
        $(document.body).infinite(50);
        var loading = false;  //状态标记
        $(document.body).infinite().on("infinite", function() {
            if(loading) return;
            loading = true;
            pageNum =pageNum+1;
            if(pageNum<=totalPage){
                initData(pageNum);
            }else{
                $.toast("加载完毕...")
            }
        });

        function initData(pageNum){
            $.ajax({
                url:"/weixin/mine/ajaxMineRoom",
                data:{},
                method:"post",
                success:function(resp){
                    if(resp.result){
                        var temp = $("#template").html();
                        if(resp.data.list.length>0){
                            var content = Mustache.render(temp,{items:resp.data});
                            $("#content").html(content);
                            loading = false;
                            totalPage = resp.data.totalPage
                        }else{
                            $("#content").html("<div class='no-data'>暂无任何记录信息</div>");
                        }
                    }
                }
            })
        }
        initData(pageNum);


        $("#content").on("click",".weui-media-box",function(){
            var obj_id = $(this).attr("data-obj_id");
            var id = $(this).attr("data-id");
            var status = $(this).attr("data-status");
            var titleTip = "系统消息";
            var textTip = "确定要进行当前操作吗？";
            $.actions({
                actions: [{
                    text: "查看详情",
                    onClick: function () {
                        console.log(status);
                        if(status=="等待支付"){
                            window.location.href="#(contextPath)/weixin/room/roomOrderPreview?id="+id;
                        }else{
                            window.location.href="#(contextPath)/weixin/room/roomDetail?id="+obj_id
                        }

                    }
                }, {
                    text: "取消房间预订",
                    onClick: function () {
                        $.confirm({
                            title: titleTip,
                            text: textTip,
                            onOK: function () {
                                var config = {
                                    "url": "#(contextPath)/weixin/room/cancelRoomOrder",
                                    "data": {id:id},
                                    "successCallBack": function (resp) {
                                        if(resp.result){
                                            $.alert(resp.data,function(){
                                                window.location.reload()
                                            })
                                        }else{
                                            $.alert(resp.data)
                                        }
                                    }
                                }
                                var ajax = new AjaxUtils(config);
                                ajax.executeRequest();
                            },
                            onCancel: function () {
                            }
                        });
                    }
                }]
            });
        });
    });





</script>
#end
